﻿@using HPIT.RentHouse.DTO
@model HouseAddDTO
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout1.cshtml";
    var AttachmentList = ViewBag.AttachmentList as List<AttachmentDTO>;
}
<!--日期插件-->
<script src="~/My97DatePicker/WdatePicker.js"></script>
<!--解决Ueditor编辑器乱码的问题-->
<script charset="gbk" src="~/gbk-net/lang/zh-cn/zh-cn.js"></script>
<!--Ueditor编辑器插件-->
<script src="~/gbk-net/ueditor.config.js"></script>
<script src="~/gbk-net/ueditor.all.js"></script>
<script src="~/gbk-net/ueditor.parse.js"></script>

<form action="@Url.Action("AddHouseList","House")" method="post" class="form form-horizontal" id="form-admin-add">
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>区域：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <span class="select-box">
                @Html.DropDownListFor(a => a.RegionId, ViewBag.RegionList as IEnumerable<SelectListItem>, "==请选择==", new { @class = "select" })
            </span>
        </div>
        <label class="form-label col-xs-2 col-sm-1">小区：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <select class="select" id="Clear_CommunityId" name="CommunityId">
                <option value="">==请选择==</option>
            </select>
        </div>
        <label class="form-label col-xs-2 col-sm-1">房型：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <span class="select-box">
                @Html.DropDownListFor(a => a.RoomTypeId, ViewBag.RoomTypeList as IEnumerable<SelectListItem>, "==请选择==", new { @class = "select" })
            </span>
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3">地址：</label>
        <div class="formControls col-xs-5 col-sm-4">
            <input type="text" class="input-text" placeholder="详细地址" name="Address">
        </div>
        <label class="form-label col-xs-3 col-sm-2">月租金：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <input type="text" class="input-text" name="MonthRent">
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <span class="select-box">
                @Html.DropDownListFor(a => a.StatusId, ViewBag.StatusList as IEnumerable<SelectListItem>, "==请选择==", new { @class = "select" })
            </span>
        </div>
        <label class="form-label col-xs-2 col-sm-1">面积：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <input type="text" class="input-text" placeholder="平米" name="Area">
        </div>
        <label class="form-label col-xs-2 col-sm-1">装修：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <span class="select-box">
                @Html.DropDownListFor(a => a.DecorateStatusId, ViewBag.DecorateStatusList as IEnumerable<SelectListItem>, "==请选择==", new { @class = "select" })
            </span>
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>楼层：</label>
        <div class="formControls col-xs-2 col-sm-1">
            <input type="text" class="input-text" placeholder="所在层" name="FloorIndex">
        </div>
        <div class="formControls col-xs-2 col-sm-1">
            <input type="text" class="input-text" placeholder="总层数" name="TotalFloorCount">
        </div>
        <label class="form-label col-xs-2 col-sm-1">户型：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <span class="select-box">
                @Html.DropDownListFor(a => a.TypeId, ViewBag.TypeList as IEnumerable<SelectListItem>, "==请选择==", new { @class = "select" })
            </span>
        </div>
        <label class="form-label col-xs-2 col-sm-1">朝向：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <input type="text" class="input-text" name="Direction">
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3">可看房时间：</label>
        <div class="formControls col-xs-4 col-sm-3">
            <input name="LookableDateTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
            <img src="~/My97DatePicker/skin/datePicker.gif">
        </div>
        <label class="form-label col-xs-3 col-sm-2">入住时间：</label>
        <div class="formControls col-xs-4 col-sm-3">
            <input name="CheckInDateTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
            <img src="~/My97DatePicker/skin/datePicker.gif">
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3">业主姓名：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <input type="text" class="input-text" name="OwnerName">
        </div>
        <label class="form-label col-xs-4 col-sm-3">业主电话：</label>
        <div class="formControls col-xs-3 col-sm-2">
            <input type="text" class="input-text" name="OwnerPhoneNum">
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3">房源描述：</label>
        <div class="formControls col-xs-5 col-sm-4">
            <script id="container" name="Description" type="text/plain">

            </script>
        </div>
    </div>

    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-3">配置设置：</label>
        <div class="formControls col-xs-8 col-sm-7">
            <dl class="permission-list">
                <dd>
                    <dl class="cl permission-list2">
                        @foreach (AttachmentDTO attachmentDTO in AttachmentList)
                        {
                            <dt>
                                <label class="">
                                    <input type="checkbox" name="AttachmentIds" value="@attachmentDTO.Id" />
                                    @attachmentDTO.Name
                                </label>
                            </dt>
                        }
                    </dl>
                </dd>
            </dl>
        </div>
    </div>

    <div class="row cl">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
        </div>
    </div>
</form>

@section footScript{
    <script type="text/javascript">
        //实例化Ueditor编辑器
        var ue = UE.getEditor('container', {
            autoHeightEnabled: false,  //是否自动增高
            initialFrameHeight: 300,  //初始化编辑器高度
            initialFrameWidth: 750,  //初始化编辑器宽度
        });

        $(function () {
            //区域小区二级联动
            $("#RegionId").change(function () {
                //获取当前选中的区域Id
                var regionId = $(this).val();
                if (regionId) {
                    //发送Ajax请求获取小区信息
                    $.post("@Url.Action("GetCommunityList", "House")", {
                        regionId:
                            regionId
                    }, function (data) {
                        //清除现有的小区信息
                        $("#Clear_CommunityId").empty();
                        //添加新的Option
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            var option = "<option value=" + item.Id + ">" + item.Name + "</option>";
                            //把通过区域Id循环筛选出的小区信息添加进Option中
                            $("#Clear_CommunityId").append(option);
                        }
                    }, "json");
                }
            })

            $("#form-admin-add").validate({
                rules: {
                    Address: {
                        required: true,
                        maxlength: 10
                    },
                    MonthRent: {
                        required: true,
                        number: true,
                        maxlength: 4
                    },
                    Area: {
                        required: true,
                        number: true,
                        maxlength: 3
                    },
                    FloorIndex: {
                        required: true,
                        number: true
                    },
                    TotalFloorCount: {
                        required: true,
                        number: true
                    },
                    Direction: {
                        required: true,
                        maxlength: 2
                    },
                    OwnerName: {
                        required: true,
                        maxlength: 6
                    },
                    OwnerPhoneNum: {
                        required: true,
                        isPhone: true
                    },
                },
                submitHandler: function (form) {
                    //使用ajax方式提交表单
                    $(form).ajaxSubmit({
                        success: function (data) {
                            console.log(data)
                            if (data.State == 1) {
                                parent.location.reload();
                            } else {
                                layer.msg(data.ErrorMessage, { icon: 2 });
                            }
                        }
                    })
                }
            })
            //获取文本编辑器里的内容
            var con = UE.getEditor('editor').getContent()
        })
    </script>
}
